<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="d1">
<input type="text" id="d2">
<!--<input type="button" value="加" onclick="f1()">-->
<!--<input type="button" value="减" onclick="f2()">-->
<!--<input type="button" value="乘" onclick="f3()">-->
<!--<input type="button" value="除" onclick="f4()">-->
<input type="button" value="加" onclick="f('加')">
<input type="button" value="减" onclick="f('减')">
<input type="button" value="乘" onclick="f('乘')">
<input type="button" value="除" onclick="f('除')">
<div>结果 : </div>

<script>

  let d1 = document.querySelector("#d1");
  let d2 = document.querySelector("#d2");
  let div = document.querySelector("div");

/*  function f1(){
    if (isNaN(d1.value) || isNaN(d2.value)){
      div.innerText = "输入错误!"
      return;
    }
    div.innerText = "结果="+(parseFloat(d1.value)+parseFloat(d2.value));
  }
  function f2(){
    if (isNaN(d1.value) || isNaN(d2.value)){
      div.innerText = "输入错误!"
      return;
    }
    div.innerText = "结果="+(d1.value-d2.value);
  }
  function f3(){
    if (isNaN(d1.value) || isNaN(d2.value)){
      div.innerText = "输入错误!"
      return;
    }
    div.innerText = "结果="+(d1.value*d2.value);
  }
  function f4(){
    if (isNaN(d1.value) || isNaN(d2.value)){
      div.innerText = "输入错误!"
      return;
    }
    div.innerText = "结果="+(d1.value/d2.value);
  }*/

  function f(value){
    if (isNaN(d1.value) || isNaN(d2.value)){
      div.innerText = "输入错误!"
      return;
    }
    switch (value){
      case '加':
        div.innerText = "结果="+(parseFloat(d1.value)+parseFloat(d2.value));
        break;
      case '减':
        div.innerText = "结果="+(d1.value-d2.value);
        break;
      case '乘':
        div.innerText = "结果="+(d1.value*d2.value);
        break;
      case '除':
        div.innerText = "结果="+(d1.value/d2.value);
        break;
    }
  }


</script>



</body>
</html>